﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WM.WinForm.Core.Extension
{
    /// <summary>
    /// RichTextBox 扩展处理
    /// </summary>
    public static class RichTextBoxExt
    {
        /// <summary>
        /// 追加自定义的文本
        /// </summary>
        /// <param name="txbControl"></param>
        /// <param name="content"></param>
        /// <param name="fontStyle"></param>
        /// <param name="fontColor"></param>
        public static void AppendRTFText(this RichTextBox txbControl, string content, Font fontStyle, Color fontColor)
        {
            int startIndex = txbControl.TextLength;
            txbControl.AppendText(content);
            // 设置选中内容
            //txbControl.Select(startIndex, content.Length);

            txbControl.SelectionStart = startIndex;
            txbControl.SelectionLength = content.Length;

            txbControl.SelectionFont = fontStyle;
            txbControl.SelectionColor = fontColor;
        }
        /// <summary>
        /// 追加自定义的文本
        /// </summary>
        /// <param name="txbControl"></param>
        /// <param name="content"></param>
        /// <param name="fontStyle"></param>
        /// <param name="fontColor"></param>
        public static void AppendRTFText(this RichTextBox txbControl, string content, Color fontColor)
        {
            int startIndex = txbControl.Text.Length;
            txbControl.AppendText(content);
            // 设置选中内容
            txbControl.Select(startIndex, content.Length);
            txbControl.SelectionColor = fontColor;
        }
        /// <summary>
        /// 将指定的内容进行高亮显示
        /// </summary>
        /// <param name="txbControl">组件</param>
        /// <param name="startIndex">开始索引</param>
        /// <param name="length">内容长度</param>
        /// <param name="fontColor">指定颜色</param>
        public static void SetRTFHighlight(this RichTextBox txbControl, int startIndex, int length, Color fontColor)
        {
            // 设置选中内容
            txbControl.Select(startIndex, length);
            txbControl.SelectionColor = fontColor;
        }
    }
}
